<?php
class bestmodel extends CI_Model {
	function bestmodel() {
		parent::__construct();
		$this->load->database();
	}
	
	function get_price_ids($provider_id) {
		$this->db->where('provider_id', $provider_id);
		$query = $this->db->get('provider_pricepolicy');
		if($query->num_rows() >= 1) {
			$result = $query->result_array();
			$pprices = array();
			$index = 0;
			foreach ($result as $item) {
				$pprices[$index] = $item['pricePolicy_id'];
				$index++;
			}
			return $pprices;
		}else {
			return NULL;
		}
	}
	
	
	function get_price_icon($id) {
		$this->db->where('id', $id);
		$query = $this->db->get('pricepolicy');
		if($query->num_rows() >= 1) {
			$result = $query->first_row();
			$icon = $result->icon;
			return $icon;
		}else {
			return NULL;
		}		
	}
	
	function get_price_icons($provider_id) {
		$price_ids = $this->get_price_ids($provider_id);
		$size = count($price_ids);
		$icons = array();
		$index = 0;
		
		for($i =0; $i < $size; $i++) {
			$icons[$index] = $this->get_price_icon($price_ids[$index]);
			$index++;
		}
		return $icons;
	}
	
	function get_time_ids($provider_id) {
		$this->db->where('provider_id', $provider_id);
		$query = $this->db->get('provider_timepolicy');
		if($query->num_rows() >= 1) {
			$result = $query->result_array();
			$times = array();
			$index = 0;
			foreach ($result as $item) {
				$times[$index] = $item['timePolicy_id'];
				$index++;
			}
			return $times;
		}else {
			return NULL;
		}	
	}
	
	function get_time_icon($id) {
		$this->db->where('id', $id);
		$query = $this->db->get('timepolicy');
		if($query->num_rows() >= 1) {
			$result = $query->first_row();
			$icon = $result->icon;
			return $icon;
		}else {
			return NULL;
		}		
	}
	
	function get_time_icons($provider_id) {
		$time_ids = $this->get_time_ids($provider_id);
		$size = count($time_ids);
		$icons = array();
		$index = 0;
		
		for($i =0; $i < $size; $i++) {
			$icons[$index] = $this->get_time_icon($time_ids[$index]);
			$index++;
		}
		return $icons;
	}
	
	function getProvider() {
		$query =  $this->db->get('provider');
		return $query->result_array();
	}
}